package com.ophiux.cs.application.consult.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ophiux.cs.application.consult.dto.GetCSUserInfoRequest;
import com.ophiux.cs.application.consult.dto.GetCSUserInfoResponse;
import com.ophiux.cs.application.consult.service.ICSUserQueryAppService;
import com.ophiux.cs.application.core.Result;
import com.ophiux.cs.domain.consult.model.entity.CSUser;
import com.ophiux.cs.domain.consult.repositories.IUserInfoRepository;
import com.ophiux.utils.exception.OphiuxRepositoryException;

/**
 * 获取咨询用户信息
 * @author chenh
 *
 */
@Service("cSUserQueryAppService")
public class CSUserQueryAppService implements ICSUserQueryAppService{

	@Autowired
	IUserInfoRepository cSUserInfoRepository;	//用户信息仓储
	
	@Override
	public Result<GetCSUserInfoResponse> getCSUserInfo(GetCSUserInfoRequest request) {
		
		String targetAcc = request.getTARGET_ACC();
		CSUser csUser = null;
		try {
			csUser = cSUserInfoRepository.getCSUserByTargetACC(targetAcc);
		} catch (OphiuxRepositoryException e) {
			e.printStackTrace();
			return Result.fail("", e.getExceptionMessage());
		}
		if(csUser == null) {
			return Result.fail("", "用户未找到");
		}
		//获取成功，转为dto
		GetCSUserInfoResponse resp = new GetCSUserInfoResponse();
		resp.setTARGET_ID(csUser.getTARGET_ID());
		resp.setTARGET_ACC(csUser.getTARGET_ACC());
		
		return Result.success(resp);
	}

}
